/*
============================================================================
 Name        : PodcastPlugin.h
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : CPodcastPlugin declaration
============================================================================
*/

#ifndef __CPODCASTPLUGIN__
#define __CPODCASTPLUGIN__

#include "PluginInterface.h"	//CPluginInterface
#include "RssReader.h"			//MReaderObserver
#include "MStreamBufferObserver.h"		//MStreamBufferObserver

#include <aknwaitdialog.h>		//CAknWaitDialog, MProgressDialogCallback

class CEikMenuPane;
class CPodcastPlayer;
class CPodcastUI;

// An implementation of the CPluginInterface definition
class CPodcastPlugin :	public CPluginInterface,
						public MReaderObserver,
						public MStreamBufferObserver
{
public:
	// Standardised safe construction which leaves nothing the cleanup stack.
	static CPodcastPlugin* NewL(TAny* aInitParams);
	// Destructor	
	~CPodcastPlugin();

private:
	// Construction
	CPodcastPlugin(TAny* aParams);
	void ConstructL();


public: //from CPluginInterface
	const TDesC& GetMenuText();
	TInt GetMenuCommand();
	void AddExtraMenu(CEikMenuPane* aMenuPane);
	void HandleCommandL(TInt aCommand);
	TKeyResponse HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);

	void Draw(CWindowGc& aGc, const TRect& aRect) const;

	void SetContainer(MPluginContainer* aContainer);

	void Activate();
	void Deactivate();

	//Colors
	TRgb BackBorderColor() const;
	TRgb BackShadowColor() const;
	TRgb BackColor() const;
	TRgb InsideBorderColor() const;
	TRgb InsideColor() const;
	TRgb ForeColor() const;


public: //from MPlayerAdapter
	void PlayL();
	void PauseL() {};
	void StopL();

	TBool IsReadyToPlay();
	TBool IsReadyToPause() { return EFalse; };
	TBool IsReadyToStop();

	TInt Volume();
	void SetVolume(TInt aVolume);


private: //from MReaderObserver
	void DocumentEnd();
	void RunError(const TDesC& aErrorDesc, TInt aError);


private: //from MStreamBufferObserver
	void BufferStateChanged(TBool aIsBuffering, TInt aPercent);
	void Finished();


private: //new functions
	void AddResourceFileL();
	void SelectRssFeedL();
	void DownloadAndParseRssFeed(const TDesC& aRssFeed);
	void LoadRssFeed(TRssFeed* aRssFeed);
	void ChangeState();

	static TInt OnImageIsReady(TAny* aAny);


private:
	//Plugin state
	enum TState
	{
		EStateNotReady,    //Not ready to play
		EStateReadyToPlay, //Ready to play
		EStatePlaying      //Playing
	} iState;

	// Parameters taken from client
	CPluginInterface::TPluginInterfaceInitParams* iInitParams;

	//Resource compiled file id
	TInt iOffset;

	//Underlying rss feed reader
	CRssReader* iRssReader; 
	TRssFeed* iRssFeed; //Reference to rss feed

	//Player
	CPodcastPlayer* iPodcastPlayer;

	//UI class manager
	CPodcastUI* iPodcastUI;

	//Callback after image is ready to be drawn
	TCallBack iOnImageReadyCallback;
};  

#endif
